﻿using System;
using System.Collections;
using System.Windows.Forms;
using Mota.EditModule;
namespace Mota.XMLControls
{
    public abstract class GuiListBox:GuiControl,IDatasourceObject
    {
        public override void Add(GuiControl guiControl)
        {
           //empty
        }

        public override IEnumerator GetEnumerator()
        {
            return null;
        }

        public virtual bool IsValid
        {
            get
            {
                return true;
            }
        }
        public override void Accept(GuiVisitor visitor)
        {
            visitor.Visit(this);
        }

        public override bool IsSimple
        {
            get
            {
                return false;
            }
        }

        public bool UseOnlyActive { get; set; }

        public bool UseGroupBy { get; set; }
        public bool IsEditable { get; set; }

        public override void SetPropertyValue(String propertyName, String propertyValue)
        {
            base.SetPropertyValue(propertyName, propertyValue);
            // chesh null or empty
            if (String.IsNullOrEmpty(propertyValue) || String.IsNullOrEmpty(propertyValue))
                return;

            // choose properties only from allowed 
            switch (propertyName)
            {
                case "UseOnlyActive":
                    bool parsedUseOnlyActive;
                    if (bool.TryParse(propertyValue, out parsedUseOnlyActive))
                    {
                        this.UseOnlyActive = parsedUseOnlyActive;
                    }
                    break;
                case "UseGroupBy":
                    bool parsedUseGroupBy;
                    if (bool.TryParse(propertyValue, out parsedUseGroupBy))
                    {
                        this.UseGroupBy = parsedUseGroupBy;
                    }
                    break;
                case "IsEditable":
                    bool parsedIsEditable;
                    if (bool.TryParse(propertyValue, out parsedIsEditable))
                    {
                        this.IsEditable = parsedIsEditable;
                    }
                    break;
            }
        }



        public abstract void Refresh(ConnectionConfigs configs, BindingSource mainBs);
    }
}
